//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbKhoaHoc
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbKhoaHoc_SelectAll", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbKhoaHoc_SelectTop", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbKhoaHoc OTbKhoaHoc)
        {
            SqlParameter[] pr = new SqlParameter[6];
            pr[0] = new SqlParameter(@"TenKhoaHoc", OTbKhoaHoc.TenKhoaHoc);
            pr[1] = new SqlParameter(@"NoiDung", OTbKhoaHoc.NoiDung);
            pr[2] = new SqlParameter(@"DiaDiemHoc", OTbKhoaHoc.DiaDiemHoc);
            pr[3] = new SqlParameter(@"ThoiGianBatDau", OTbKhoaHoc.ThoiGianBatDau);
            pr[4] = new SqlParameter(@"ThoiGianKetThuc", OTbKhoaHoc.ThoiGianKetThuc);
            pr[5] = new SqlParameter(@"NamHoc", OTbKhoaHoc.NamHoc);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbKhoaHoc_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbKhoaHoc OTbKhoaHoc)
        {
            SqlParameter[] pr = new SqlParameter[7];
            pr[0] = new SqlParameter(@"MaKhoaHoc", OTbKhoaHoc.MaKhoaHoc);
            pr[1] = new SqlParameter(@"TenKhoaHoc", OTbKhoaHoc.TenKhoaHoc);
            pr[2] = new SqlParameter(@"NoiDung", OTbKhoaHoc.NoiDung);
            pr[3] = new SqlParameter(@"DiaDiemHoc", OTbKhoaHoc.DiaDiemHoc);
            pr[4] = new SqlParameter(@"ThoiGianBatDau", OTbKhoaHoc.ThoiGianBatDau);
            pr[5] = new SqlParameter(@"ThoiGianKetThuc", OTbKhoaHoc.ThoiGianKetThuc);
            pr[6] = new SqlParameter(@"NamHoc", OTbKhoaHoc.NamHoc);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbKhoaHoc_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaKhoaHoc)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaKhoaHoc",MaKhoaHoc);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbKhoaHoc_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbKhoaHoc SelectByID(int MaKhoaHoc)
        {
            ETbKhoaHoc OTbKhoaHoc = new ETbKhoaHoc();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaKhoaHoc",MaKhoaHoc);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbKhoaHoc_SelectByID", pr);
            if (idr.Read())
              OTbKhoaHoc = GetOneTbKhoaHoc(idr);
            idr.Close();
            idr.Dispose();
            return OTbKhoaHoc;
        }
//-----------------------------------------------------------//
        private static ETbKhoaHoc GetOneTbKhoaHoc(IDataReader idr)
       {
            ETbKhoaHoc OTbKhoaHoc = new ETbKhoaHoc();
                if (idr["MaKhoaHoc"] != DBNull.Value)
                    OTbKhoaHoc.MaKhoaHoc = (int)idr["MaKhoaHoc"];
                if (idr["TenKhoaHoc"] != DBNull.Value)
                    OTbKhoaHoc.TenKhoaHoc = (string)idr["TenKhoaHoc"];
                if (idr["NoiDung"] != DBNull.Value)
                    OTbKhoaHoc.NoiDung = (string)idr["NoiDung"];
                if (idr["DiaDiemHoc"] != DBNull.Value)
                    OTbKhoaHoc.DiaDiemHoc = (string)idr["DiaDiemHoc"];
                if (idr["ThoiGianBatDau"] != DBNull.Value)
                    OTbKhoaHoc.ThoiGianBatDau = (string)idr["ThoiGianBatDau"];
                if (idr["ThoiGianKetThuc"] != DBNull.Value)
                    OTbKhoaHoc.ThoiGianKetThuc = (string)idr["ThoiGianKetThuc"];
                if (idr["NamHoc"] != DBNull.Value)
                    OTbKhoaHoc.NamHoc = (int)idr["NamHoc"];
            return OTbKhoaHoc;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaKhoaHoc)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaKhoaHoc",MaKhoaHoc);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbKhoaHoc_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbKhoaHoc> ListAll()
        {
            List<ETbKhoaHoc> list = new List<ETbKhoaHoc>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbKhoaHoc_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbKhoaHoc(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbKhoaHoc> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbKhoaHoc> list = new List<ETbKhoaHoc>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbKhoaHoc_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbKhoaHoc(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}